package com.itheima.mapper;

import com.itheima.pojo.Report;
import com.itheima.pojo.ReportClazzCount;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StudentMapper {
    List<Student> selectPage(StudentQueryParam studentQueryParam);

    void deleteByIds(List<Integer> ids);
    @Insert("insert into student(name,no,gender,phone,id_card,is_college,address,degree,graduation_date,clazz_id,create_time,update_time)" +
            " values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insertStudent(Student student);
    @Select("select *from student where id =#{id}")
    Student selectById(Integer id);
    @Update("update student set name=#{name},no=#{no},gender=#{gender},phone=#{phone},id_card=#{idCard},is_college=#{isCollege},address=#{address},degree=#{degree},graduation_date=#{graduationDate},clazz_id=#{clazzId},update_time=#{updateTime} where id =#{id}")
    void updateStudent(Student student);
//    @Update("update student set violation_count =violation_count+1,violation_score=violation_score+#{score} where id=#{id}")
    @Update("update student set violation_count = violation_count+1,violation_score = violation_score + #{score} where id = #{id}")
    void updateScore(Integer id, Integer score);
    @Select("select degree name,count(degree) value from student group by degree;")
    List<Report> studentCount();
    @Select("select c.name name , count(s.clazz_id) value from clazz c left join student s on c.id =s.clazz_id group by c.id")
    List<Report> studentCountPop();
    @Select("select *from student where clazz_id=#{clazzId}")
    List<Student> selectByclazzId(Integer clazzId);
}
